<?php


/**
 * Widget class.
**/
class Widget extends EMongoEmbeddedDocument {
  
  const IS_PUBLIC = 0;
  const IS_FRIEND = 1;
  const IS_PRIVATE = 2;
  
  	public $wid;
  	public $pid;
  	public $classname;
  	public $cntitle;
	public $viewperm= self::IS_PUBLIC;
	public $cmtperm;
	public $tranperm;
	public $trandate;
	public $orig_wid;
	public $createdate;
	public $updatedate;
	public $style;
	public $attribute;
  	// public $attribute = array();
  	// public $styles = array();
 
  /**
  * This method have to be defined in every Model
  * @return string MongoDB collection name, witch will be used to store documents of this model
  */
  public function getCollectionName() {
    return 'widget';
  }


    /**
     * This method should return simple array that will define field names for embedded
     * documents, and class to use for them
	 *   	 var style={'background-color':'#000000',opacity:1};
	   var jwidget={widget_id:"<?php echo $widget_id?>",'classname':"<?php echo $classname?>",'styles':style};
     */ 
    public function embeddedDocuments()
    {
        return array(
            // property field name => class name to use for this embedded document
            'style' => 'Style',
            'attribute'=>'Attribute',
        );
    }
	
  /**
   * This method have to be defined in every model, like with normal CActiveRecord
   */
  public static function model($className = __CLASS__) {
    return parent :: model($className);
  }

  public static function findByUid($uid) {
    return  self :: model()->findByAttributes(array ('uid' => $uid));
  }

}